package cn.t.web.device;

import cn.t.core.mode.PageInfoDTO;
import cn.t.core.mode.PageQueryDTO;
import cn.t.facade.device.DeviceOpenRecordFacade;
import cn.t.listener.CustomCellWriteWidthConfig;
import cn.t.request.OpenRecordReq;
import cn.t.vo.order.OpenRecordVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 设备管理 - 开门记录
 * @author l
 */
@Slf4j
@RestController
@RequestMapping("/open/record")
@AllArgsConstructor
public class DeviceOpenRecordController {
    private final DeviceOpenRecordFacade deviceOpenRecordFacade;

    /**
     * 开门记录列表
     */
    @PostMapping("/page")
    public PageInfoDTO<OpenRecordVO> openRecordPage(@RequestBody PageQueryDTO<OpenRecordReq> request) {
        return this.deviceOpenRecordFacade.openRecordPage(request);
    }

    /**
     * 导出筛选后的开门记录
     */
    @PostMapping("/export")
    public void exportOpenRecord(HttpServletResponse response, @RequestBody OpenRecordReq req) {
        this.deviceOpenRecordFacade.exportOpenRecord(response, req, new CustomCellWriteWidthConfig());
    }
}

